import abc
from typing import Callable, Iterable, Iterator, Sized, TypeVar

T = TypeVar("T")


class SizedIterable(Iterable[T], Sized, abc.ABC):
    @abc.abstractmethod
    def __len__(self) -> int:
        pass

    @abc.abstractmethod
    def __iter__(self) -> Iterator[T]:
        pass


class SizedIterableByHeader(SizedIterable[T]):
    def __init__(self, iter_func: Callable[[], Iterable[int | T]]):
        self._iter_func = iter_func
        self._size = next(iter(self._iter_func()))

    def __len__(self) -> int:
        return self._size

    def __iter__(self):
        iterator = iter(self._iter_func())
        next(iterator)
        return iterator
